
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/skins/_all-skins.min.css">
    <!-- Validator style -->
    <link href="<%=basePath %>bootstrap/bootstrapvalidator/dist/css/bootstrapValidator.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
</head>
<body class="skin-blue sidebar-mini" style="height: auto; min-height: 100%;">

<div class="wrapper" style="height: auto; min-height: 100%;">
    <!-- header头部页面 -->
    <jsp:include page="../commend/top.jsp"/>
    <!-- Left side column. contains the logo and sidebar -->
    <jsp:include page="../commend/left.jsp"/>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" style="min-height: 800px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>

                <small>填报周期管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li class="active">填报周期管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Info boxes -->
            <!-- Main row -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">填报周期列表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body ">
                            <div class="row ">
                                <div class="col-md-12">
                                    <div id="toolbar" class="btn-group">
                                        <button id="btn_save" type="button" class="btn btn-default " style="margin-right: 10px">
                                            <span class="glyphicon " aria-hidden="true">添加</span>
                                        </button>

                                    </div>
                                    <table
                                            id="cycletable"
                                            data-toggle="table"
                                            data-url="<%=basePath %>/systemcycle/selectSystemCycle"
                                            data-toolbar="#toolbar"
                                            data-cache="false"
                                            data-pagination="true"
                                            data-height="600"
                                            class="table"
                                            style="font-size:100%;"
                                    >
                                        <thead>
                                        <tr>
                                            <th data-field="cycledate">评价期次</th>
                                            <th data-field="begindatestr" >开始评价日期</th>
                                            <th data-field="enddatestr" >结束评价日期</th>
                                            <th data-field="id" data-width="15%" data-formatter="caozuoformatter" data-events="operateEvent">操作</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- ./box-body -->
                        <div class="box-footer">
                            <div class="row">

                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
        <div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">填报周期管理</h4>
                    </div>
                    <div class="modal-body">
                        <form action="#">
                            <div class="form-group">
                                <label for="cycledate">上报周期:</label>
                                <input type="text" class="form-control" id="cycledate" name="cycledate" data-date-format="yyyy-mm">
                            </div>
                            <div class="form-group">
                                <label for="begindate">开始日期:</label>
                                <input type="text" class="form-control" id="begindate" name="begindate" data-date-format="yyyy-mm-dd">
                            </div>
                            <div class="form-group">
                                <label for="enddate">结束日期:</label>
                                <input class="form-control" id="enddate" name="enddate" data-date-format="yyyy-mm-dd">
                            </div>
                            <input type="hidden" name="id" id="id">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"  id="btn_sure">确定</button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- /.content-wrapper -->
    <!-- footer-->
    <jsp:include page="../commend/footer.jsp"/>
</div>
<!-- jQuery 3 -->
<script src="<%=basePath %>bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<%=basePath %>bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath %>bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<%=basePath %>dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="<%=basePath %>dist/js/demo.js"></script>
<!-- Validator 3.3.7 -->
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/bootstrapValidator.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/language/zh_CN.js"></script>
<!-- bootstrap-table -->
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- bootbox -->
<script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
<script src="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>
<script>
    function caozuoformatter() {
        var buttonarray = new Array();
        buttonarray[0] = '<button type="button" class="RoleOfedit btn btn-primary  btn-sm" style="margin-right:15px;">修改</button>';
        buttonarray[1] = '<button type="button" class="RoleOfdel btn btn-primary  btn-sm" style="margin-right:15px;">删除</button>';

        return buttonarray.join('');
    }
    function format(date){
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        return Y+M+D;
    }
    window.operateEvent = {
        'click .RoleOfedit': function (e, value, row, index) {
            $("#id").val(row.id);
            $("#cycledate").val(row.cycledate);
            $("#begindate").val(format(new Date(row.begindate)));
            $("#enddate").val(format(new Date(row.enddate)));
            $("#modalTable").modal({
                backdrop: 'static',
                keyboard: false
            });
        },
        'click .RoleOfdel': function (e, value, row, index) {
            bootbox.confirm({
                message: "是否删除?",
                buttons: {
                    confirm: {
                        label: '是',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '否',
                        className: 'btn-danger'
                    }
                },
                callback: function (result) {
                    if(result){
                        $.post(getRootPath_web()+'/systemcycle/delSystemCycle',{'id':value},function (data) {
                            if(data){
                                bootbox.alert("操作成功",function () {
                                    setTimeout(function(){
                                        $("#cycletable").bootstrapTable('refresh')
                                    },320);
                                });
                            }else{
                                bootbox.alert("操作失败",function () {
                                    setTimeout(function(){
                                        $("#cycletable").bootstrapTable('refresh')
                                    },320);
                                });
                            }
                        },'json')
                    }
                }
            });
        }
    }
    $(function () {
        $("#btn_save").on("click",function () {
            $("#id").val("");
            $("#modalTable").modal({
                backdrop: 'static',
                keyboard: false
            });
        })

        $("#btn_sure").on("click",function () {
            var data = {};
            var url = '';
            if($("#id").val() == ''){
                url = getRootPath_web()+'/systemcycle/addSystemCycle';
                data = {
                    cycledate:$("#cycledate").val(),
                    begindate:$("#begindate").val(),
                    enddate:$("#enddate").val()
                }
            }else{
                url = getRootPath_web()+'/systemcycle/updateSystemCycle';
                data = {
                    cycledate:$("#cycledate").val(),
                    begindate:$("#begindate").val(),
                    enddate:$("#enddate").val(),
                    id:$("#id").val()
                }
            }
            $.post(url,data,function (data) {
                if(data){
                    bootbox.alert("操作成功",function () {
                        setTimeout(function(){
                            $('#modalTable').modal('hide')
                            $("#cycletable").bootstrapTable('refresh')
                        },320);
                    });
                }else{
                    bootbox.alert("操作失败",function () {
                        setTimeout(function(){
                            $('#modalTable').modal('hide')
                            $("#cycletable").bootstrapTable('refresh')
                        },320);
                    });
                }
            },'json')
        })
        $('#cycledate').datetimepicker({
            language:'zh-CN',
            format: 'yyyy-mm',
            autoclose: true,
            todayBtn: true,
            minView:2,
            maxView:2
        });
        $('#begindate').datetimepicker({
            language:'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            minView:2,
            maxView:2
        });
        $('#enddate').datetimepicker({
            language:'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            minView:2,
            maxView:2
        });
    })
</script>
</body>


</html>
